<?php
namespace Admin\Controller;

use Think\Controller;

class UserController extends Controller
{
    const USER = "member";
    const CONPUN = "coupon";
    private static $COUPON = 2;


    public function index()
    {
        $this->findAll("member");
        $this->show("大爷，这是UserController生成的");
        $this->test();
    }

    /**登录*/
    public function login()
    {
//        echo "登录成功！";
        //获取用户post的用户名
        $userName = isset($_GET['name']) ? $_GET['name'] : null;
        $userPwd = isset($_GET['password']) ? $_GET['password'] : null;
//        trace("获取的用户名：" . $userName . "\n" . "密码：" . $userPwd);
        if ($userName == null | $userPwd == null) {
            //账号或密码为空，直接返回登录失败
//            $data='{"status":0,"msg":"账号或密码不能为空"}';
//            $this->ajaxReturn($data,'JSON');
            $this->show('{"status":0,"msg":"账号或密码不能为空"}');
            exit();
        }
        //拿到账号和密码去查询
    }

      public function test()
      {
          echo MODULE_NAME;
          echo "\n";
          echo CONTROLLER_NAME;
          echo "\n";
          echo ACTION_NAME;
          echo "\n";
      }

    private function db($type, $db_config)
    {
        $form = M($type, null, $db_config);
        return $form;
    }

    private function findAll($type)
    {
        $sql = "SELECT * FROM " . $type;
        echo $sql;
        echo "<br>";
        $Form = $this->db($type, "DB_USER")->query($sql);
        dump($Form);
        $this->assign('list', $Form);
    }
}